<template>
    <div class="cart_container">
        <div class="cart_header">
            <input type="text" placeholder="回车搜索商品">
        </div>
        <div class="cart_main_container">
            <!-- 左侧边栏内容 -->
            <div class="cart_left_container">
                <div :class="active === index ?'cart_left_slider_active':'cart_left_slider'" 
                v-for="(item,index) in slider" :key="index"
                @click="OnActive(index)">
                    {{item}}
                </div>
            </div>
            <!-- 右侧二级分类内容 -->
            <div class="cart_right_container">
                <div class="cart_right_swiper">

                </div>
                <div class="cart_right_content">
                    <div class="right_item_container" 
                    v-for="(item,index) in category" :key="index">
                        <img :src="item.icon" alt="">
                        <div class="right_item_title">{{item.name}}</div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    data(){
        return {
            slider:[
                "所有分类","家居","配件装饰","服装","电器"
            ],
            active:0,
            items:[]
        }
    },
    computed:{
        category(){
            var tempItems = []
            this.items.forEach((ele)=>{
                if(this.active === 0){
                    tempItems = this.items
                }else if(this.active === 1){
                    if(ele.pid === 15114){
                        tempItems.push(ele)
                    }
                }else if(this.active === 2){
                    if(ele.pid === 15115){
                        tempItems.push(ele)
                    }
                }else if(this.active === 3){
                    if(ele.pid === 15116){
                        tempItems.push(ele)
                    }
                }else if(this.active === 4){
                    if(ele.pid === 15124){
                        tempItems.push(ele)
                    }
                }
            })
            return tempItems
        }
    },
    methods:{
        OnActive(index){
            this.active = index
        }
    },
    mounted(){
        this.$network.getCategory().then((res)=>{
            console.log(res.data.data)
            this.items = res.data.data
        }).catch((error)=>{
            console.log(error)
        })

        

    }
}
</script>

<style scoped>
    .cart_container {
        width: 100%;
    }
    .cart_header {
        width: 100%;
        height: 1rem;
        border-bottom: 1px solid #eeeeee;
        display: inline-flex;
        justify-content: flex-start;
        align-items: center;
    }
    .cart_header input {
        width: 70%;
        margin-left: 0.5rem;
        height: 0.8rem;
        border: 0px;
        background-color: #f5f5f5;
        border-radius: 1rem;
        text-indent: 2em;
    }
    .cart_main_container {
        width: 100%;
        height: 11.22rem;
        display: inline-flex;
        justify-content: space-between;
        align-items: center;
    }
    .cart_left_container {
        width: 28%;
        height: 100%;
        border-right: 1px solid #f5f5f5;
        /* background-color: orange; */
    }
    .cart_right_container {
        width: 70%;
        height: 100%;
        overflow: scroll;
    }
    .cart_left_slider {
        width: 100%;
        height: 1rem;
        border-left: 3px solid #fff;
        display: inline-flex;
        justify-content: center;
        align-items: center;
    }
    .cart_left_slider_active {
        width: 100%;
        height: 1rem;
        border-left: 3px solid red;
        display: inline-flex;
        justify-content: center;
        align-items: center;
        background-color: #f5f5f5;
        color: red;
    }

    .cart_right_content {
        width: 100%;
        display: inline-flex;
        justify-content: flex-start;
        align-items: center;
        flex-wrap: wrap;
    }
    .right_item_container {
        width: 33%;

    }
    .right_item_container img {
        width: 100%;
    }
    .right_item_title {
        width: 100%;
        margin-top: 0.2rem;
        display: inline-flex;
        justify-content: center;
        align-items: center;
    }

</style>